//
//  ZXViewControllerExtension.swift
//  ExtensionTest
//
//  Created by ZX on 2025/2/8.
//

import UIKit


public extension UIViewController{
    func push(_ vc: UIViewController, _ animated: Bool = true) {
        self.navigationController?.pushViewController(vc, animated: animated)
    }
    
    func pop(_ animated: Bool = true) {
        self.navigationController?.popViewController(animated: animated)
    }
    
    func hideNavi(_ hidden: Bool = true, _ animation: Bool = false) {
        self.navigationController?.setNavigationBarHidden(hidden, animated: animation)
    }
    
    func navigationControllerHidden(_ hidden: Bool = true, _ animation: Bool = false) {
        self.navigationController?.setNavigationBarHidden(hidden, animated: animation)
    }
}

extension UIViewController {
    
    func pop() {
        self.pop(true)
    }
    func push(_ vc: UIViewController) {
        self.push(vc, true)
    }
    var keyWindow: UIWindow? {
        if #available(iOS 15.0, *) {
            return view.window?.windowScene?.windows.first(where: \.isKeyWindow)
        } else {
            return UIApplication.shared.windows.filter { $0.isKeyWindow }.first
        }
    }
}
